import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/widget/app_bar_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/ink_widget.dart';
import 'package:get/get.dart';

import 'message_info_view.dart';
import 'message_logic.dart';

/// <summary>
/// author：zwb
/// dateTime： 2021/12/21 10:51
/// filePath： lib/page/my/message/message_view.dart
/// desc: 消息
/// <summary>
///
class MessagePage extends StatefulWidget {
  @override
  _MessagePageState createState() => _MessagePageState();
}

class _MessagePageState extends State<MessagePage> {
  final logic = Get.put(MessageLogic());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    init();
  }
  init()async{
    logic.getPtAndPlMessage();
    logic.getSysNotice();
    logic.getMsgCount();
  }
  @override
  Widget build(BuildContext context) {
    return GetBuilder<MessageLogic>(
      builder: (controller) {
        return Scaffold(
          appBar: appBarWidget(
              title: "消息"
          ),
          backgroundColor: Colors.white,
          body: Column(
            children: [
              InkWell(
                child: ListTile(
                  leading: Stack(
                    overflow: Overflow.visible,
                    children: [
                      InkWidget.imgAsset("pt.png"),
                      Positioned(
                        top: -5,
                        right: -10,
                        child: logic.msgCountData!.platformCount == 0 ? SizedBox():ClipOval(
                          child: Container(
                            width: 20,
                            height: 20,
                            color: Colors.red,
                            alignment: Alignment.center,
                            child: InkWidget.text("${logic.msgCountData!.platformCount}",color: Colors.white,fonSize: 12,),
                          ),
                        ),
                      ),
                    ],
                  ),
                  title: InkWidget.title("平台消息"),
                  subtitle: InkWidget.text("${logic.platformMsgList!.length == 0 ?'':logic.platformMsgList![logic.platformMsgList!.length-1].msgContent}",color: Colors.grey,),
                ),
                onTap: logic.platformMsgList!.length == 0 ? null: (){
                  Get.to(()=>MessageInfoPage(title: "平台消息",))!.then((value) => init());
                },
              ),

              Divider(color: Colors.grey.shade300,),

              InkWell(
                child: ListTile(
                  leading: Stack(
                    overflow: Overflow.visible,
                    children: [
                      InkWidget.imgAsset("xt.png"),
                      Positioned(
                        top: -5,
                        right: -10,
                        child: logic.msgCountData!.noticeCount == 0 ? SizedBox():ClipOval(
                          child: Container(
                            width: 20,
                            height: 20,
                            color: Colors.red,
                            alignment: Alignment.center,
                            child: InkWidget.text("${logic.msgCountData!.noticeCount}",color: Colors.white,fonSize: 12,),
                          ),
                        ),
                      ),
                    ],
                  ),
                  title: InkWidget.title("系统公告"),
                  subtitle: InkWidget.text("${logic.sysNoticeData!.length == 0 ?'':logic.sysNoticeData![logic.sysNoticeData!.length-1].msgContent}",color: Colors.grey,),
                ),
                onTap: (){
                  Get.to(()=>MessageInfoPage(title: "系统公告",))!.then((value) => init());
                },
              ),

              Divider(color: Colors.grey.shade300,),

              InkWell(
                child: ListTile(
                  leading: Stack(
                    overflow: Overflow.visible,
                    children: [
                      InkWidget.imgAsset("pl.png"),
                      Positioned(
                        top: -5,
                        right: -10,
                        child: logic.msgCountData!.interactiveCount == 0 ? SizedBox():ClipOval(
                          child: Container(
                            width: 20,
                            height: 20,
                            color: Colors.red,
                            alignment: Alignment.center,
                            child: InkWidget.text("${logic.msgCountData!.interactiveCount}",color: Colors.white,fonSize: 12,),
                          ),
                        ),
                      ),
                    ],
                  ),
                  title: InkWidget.title("评论"),
                  subtitle: InkWidget.text("${logic.plMsgList!.length == 0 ?'':logic.plMsgList![logic.plMsgList!.length-1].msgContent}",color: Colors.grey,),
                ),
                onTap: (){
                  Get.to(()=>MessageInfoPage(title: "评论",))!.then((value) => init());
                },
              ),
            ],
          ),
        );
      },
    );
  }

  @override
  void dispose() {
    Get.delete<MessageLogic>();
    super.dispose();
  }
}